package Dao;


import Impl.RegisterDao;
import model.ResultVO;
import org.apache.commons.dbutils.QueryRunner;
import util.C3P0Util;
import util.C3P0Util;
import util.Md5Util;

import java.sql.SQLException;

public class RegisterDaoImpl implements RegisterDao {
    @Override
    public ResultVO register(String userName, String password)  {
        String sql="insert into user (username, password) value (?,?);";
        ResultVO resultVO=new ResultVO();
        QueryRunner queryRunner=new QueryRunner(C3P0Util.getConnection());
        try {
            queryRunner.update(sql,new Object[]{userName, Md5Util.stringToMD5(password)});
            resultVO.setMsg("注册成功");
            resultVO.setResult("ok");
        } catch (SQLException throwables) {
            resultVO.setMsg("注册失败");
            resultVO.setResult("false");
        }
        return resultVO;
    }

    public static void main(String[] args) throws SQLException {
        RegisterDao registerDao=new RegisterDaoImpl();
        System.out.println(registerDao.register("ls", "sdfdf").getMsg());
    }
}
